export default {
  namespaced: true, // 开启命名空间
  state: {
    address: uni.getStorageSync("address"), // 收货地址
    token: uni.getStorageSync("token"),
    redirectUrl: null, // 重定向的地址
    userInfo: uni.getStorageSync("userInfo"), // 用户信息
  },
  getters: {
    // 收货地址
    getAddress(state) {
      return state.address;
    },

    getAddressStr(state) {
      return (
        state.address &&
        `${state.address.provinceName}${state.address.cityName}${state.address.countyName}${state.address.detailInfo}`
      );
    },
    getToken(state) {
      return state.token;
    },
    // 重定向的地址
    getRedirectUrl(state) {
      return state.redirectUrl;
    },
    // 用户信息
    getUserInfo(state) {
      return state.userInfo;
    },
  },
  mutations: {
    // 收货地址
    setAddress(state, address) {
      state.address = address;
      // 保存到本地
      uni.setStorageSync("address", address);
    },
    setRedirectUrl(state, redirectUrl) {
      state.redirectUrl = redirectUrl;
    },
    setToken(state, token) {
      state.token = token;
      // 保存到本地
      uni.setStorageSync("token", token);
    },
    // 用户信息
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
      // 保存到本地
      uni.setStorageSync("userInfo", userInfo);
    },
  },
};
